package com.tiantian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tiantian.dao.BindingPlatformAccountsRepository;
import com.tiantian.datajpa.service.impl.GenericServiceImpl;
import com.tiantian.domain.Bindingplatformaccounts;
import com.tiantian.service.BindingPlatformAccountsService;

/**
 * @description 买手绑定任务平台账号
 */
@Service
@Transactional
public class BindingPlatformAccountsServiceImpl extends GenericServiceImpl<Bindingplatformaccounts, String> implements BindingPlatformAccountsService {
	private BindingPlatformAccountsRepository bandBindingPlatformAccountsRepository;

	@Autowired
	public void setBandBindingPlatformAccountsRepository(BindingPlatformAccountsRepository bandBindingPlatformAccountsRepository) {
		super.setGenericDAO(bandBindingPlatformAccountsRepository);
		this.bandBindingPlatformAccountsRepository = bandBindingPlatformAccountsRepository;
	}

	public List<Map<String, Object>> list(Map<String, String> searchMap) {
		StringBuilder sql = new StringBuilder();
		Map<String, Object> params = new HashMap<String, Object>();
		sql.append("select a.*,b.platformid,b.platformname,c.CreditRating from BindingPlatformAccounts a ");
		sql.append(" left join TaskActionPlatform b on b.PlatformID=a.PlatformID ");
		sql.append(" left join PlatformCreditRating c on c.CreditRatingNo=a.CreditRatingNo and c.PlatformID=b.PlatformID");
		sql.append(" where 1=1");
		if (searchMap != null) {

			String buyersUserID = searchMap.get("buyersUserID");
			if (StringUtils.isNotBlank(buyersUserID)) {
				sql.append(" and a.buyeruserid like :buyersUserID ");
				params.put("buyersUserID", '%' + buyersUserID.trim() + '%');
			}
		}
		List<Map<String, Object>> ret = bandBindingPlatformAccountsRepository.queryHumpListMapBySql(sql.toString(), params);
		return ret;
	}

	public List<Map<String, Object>> getCreditRating(Map<String, String> searchMap) {
		StringBuilder sql = new StringBuilder();
		Map<String, Object> params = new HashMap<String, Object>();
		sql.append("select * from PlatformCreditRating ");
		sql.append(" where 1=1");
		List<Map<String, Object>> ret = bandBindingPlatformAccountsRepository.queryHumpListMapBySql(sql.toString(), params);
		return ret;
	}

}
